package com.hbnu.iostream;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;

/**
 * 需求：使用字符输出流往指定文件中输出内容
 *
 * @author kittychen
 * @since 2025-10-11 下午 2:50
 */
public class WriterDemo {
    public static void main(String[] args) {
        String path = "E:" + File.separator + "2310" + File.separator + "writer.txt";

        File file = new File(path);

        Writer writer = null;
        try {
            writer = new FileWriter(file, true);  // true表示追加内容，false表示覆盖内容

            String content = "今天是2025-10-11，天气晴朗，适合学习Java";
            writer.write(content);

            System.out.println("文件写入成功！");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (writer != null) {
                    writer.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
